package net.lanelife.casino.caipiao.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Index;
import javax.persistence.Table;

import net.lanelife.casino.caipiao.entity.enumeration.GamePlatform;
import net.lanelife.casino.caipiao.entity.support.UserRelationEntity;
import net.lanelife.casino.common.entity.annotation.Checked;
import net.lanelife.casino.common.utils.BillNoUtils;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

@Entity
@DynamicInsert
@DynamicUpdate
@Table(name = "TB_BALANCE_EXCHANGE_RECORD", indexes = { 
	@Index(name = "IDX_BILLNO", columnList = "BILLNO"),
	@Index(name = "IDX_USER_ID", columnList = "USER_ID"),
	@Index(name = "IDX_USER_NAME", columnList = "USER_NAME"),
	@Index(name = "IDX_FLOOR", columnList = "FLOOR"),
	@Index(name = "IDX_PATH", columnList = "PATH"),
	@Index(name = "IDX_PARENT_ID", columnList = "PARENT_ID"),
	@Index(name = "IDX_PARENT_NAME", columnList = "PARENT_NAME")
})
public class BalanceExchangeRecord extends UserRelationEntity<Integer> {

	private static final long serialVersionUID = -3763091533385000623L;
	
	@Checked
	@Column(name = "BILLNO", length = 24, nullable = false)
	private String billNo = BillNoUtils.generateBillNo(BillNoUtils.PREFIX_BE);
	
	@Checked
	@Column(name = "TRANS_BILLNO", length = 24, nullable = false)
	private String transBillNo;
	
	@Checked
	@Column(name = "AMOUNT", nullable = false)
	private Double amount;
	
	@Checked
	@Column(name = "PREVIOUS_BALANCE", nullable = false)
	private Double previousBalance;
	
	@Checked
	@Enumerated(EnumType.STRING)
	@Column(name = "PLATFORM", nullable = false)
	private GamePlatform platform;
	
	@Checked
	@Enumerated(EnumType.ORDINAL)
	@Column(name = "DIRECTION", nullable = false)
	private Direction direction;
	
	@Checked
	@Enumerated(EnumType.ORDINAL)
	@Column(name = "STATUS", nullable = false)
	private Status status;
	
	@Checked
	@Enumerated(EnumType.ORDINAL)
	@Column(name = "RESULT", nullable = false)
	private Result result;
	
	@Checked
	@Column(name = "RESULT_DESCRIPTION", length = 255, nullable = false)
	private String resultDescription = "";
	
	public static enum Direction {
		/**
		 * 转入 - 从我方平台转入到对方平台
		 */
		IN, 
		/**
		 * 转出 - 从对方平台转出到我方平台
		 */
		OUT
	}
	
	public static enum Status {
		SUCCESS, FAILURE, CANCELLED
	}

	public static enum Result {
		/**
		 * 转账成功
		 */
		SUCCESS,
		/**
		 * 其他错误
		 */
		ERROR,
		/**
		 * 余额不足
		 */
		BALANCE_NOT_ENOUGH,
		/**
		 * 网络错误
		 */
		NETWORK_ERROR
	}

	public String getBillNo() {
		return billNo;
	}

	public void setBillNo(String billNo) {
		this.billNo = billNo;
	}

	public String getTransBillNo() {
		return transBillNo;
	}

	public void setTransBillNo(String transBillNo) {
		this.transBillNo = transBillNo;
	}

	public Double getAmount() {
		return amount;
	}

	public void setAmount(Double amount) {
		this.amount = amount;
	}

	public Double getPreviousBalance() {
		return previousBalance;
	}

	public void setPreviousBalance(Double previousBalance) {
		this.previousBalance = previousBalance;
	}

	public GamePlatform getPlatform() {
		return platform;
	}

	public void setPlatform(GamePlatform platform) {
		this.platform = platform;
	}

	public Direction getDirection() {
		return direction;
	}

	public void setDirection(Direction direction) {
		this.direction = direction;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public Result getResult() {
		return result;
	}

	public void setResult(Result result) {
		this.result = result;
	}

	public String getResultDescription() {
		return resultDescription;
	}

	public void setResultDescription(String resultDescription) {
		this.resultDescription = resultDescription;
	}
	
}
